package cn.skyclass.controls
{
	import mx.controls.Alert;
	import mx.rpc.Fault;

	public class AdvancedAlert extends Alert
	{
		/**
		* 错误信息对话框的图标
		*/		
		[Embed(source="/cn/skyclass/assets/alert_error.gif")]
		public static var iconError:Class;
		
		/**
		* 提示信息对话框的图标
		*/				
		[Embed(source="/cn/skyclass/assets/alert_info.gif")]
		public static var iconInfo:Class;
		
		/**
		* 确认信息对话框的图标
		*/				
		[Embed(source="/cn/skyclass/assets/alert_confirm.gif")]
		public static var iconConfirm:Class;
		
		
		/**
		 * 弹出提示信息
		 * @param message
		 * @param closehandler
		 */		
		public static function info(message:String, closehandler:Function=null):void{
			var origLabel:String = Alert.okLabel;
			Alert.okLabel = "确定";
			CustomAlert.show(message, "提示信息", Alert.OK, null, closehandler, iconInfo, Alert.OK);
			Alert.okLabel = origLabel;
		}
		
		/**
		 * 弹出错误信息提示
		 * @param message
		 * @param closehandler
		 */		
		public static function error(message:String, closehandler:Function=null):void {
			var origLabel:String = Alert.okLabel;
			Alert.okLabel = "确定";
			CustomAlert.show(message, "错误信息", Alert.OK, null, closehandler, iconError, Alert.OK);
			Alert.okLabel = origLabel;
		}
		
		/**
		 * webService 调用失败提示
		 * @param fault
		 * @param title
		 * @param closeHandler
		 */		
		public static function faultError(fault:Fault, title:String="网络错误", 
			closeHandler:Function=null):void {
			
			title = "网络错误";
			var origLabel:String = Alert.okLabel;
			Alert.okLabel = "确定";
			var content:String = "错误原因:" + fault.faultString;
			content += "\n";
			content += "错误代号:" + fault.faultCode;
			content += "\n";
			content += "详细信息:"  + fault.faultDetail;
			
			CustomAlert.show(content, title, Alert.OK, null, closeHandler, iconError, Alert.OK);
			
			Alert.okLabel = origLabel;
		}
		
		/**
		 * 确认对话框提示
		 * @param message
		 * @param closehandler
		 * @param yesLabel
		 * @param noLabel
		 */		
		public static function confirm(message:String, closeHandler:Function=null,
			yesLabel:String="是", noLabel:String="否"):void{
			
			var origLabelYes:String = Alert.yesLabel;
			var origLabelNo:String = Alert.noLabel;
			if(yesLabel=="是") yesLabel = "是";
			if(noLabel=="否") noLabel = "否";
			Alert.yesLabel = yesLabel;
			Alert.noLabel = noLabel;
			
			CustomAlert.show(message, "确认信息", Alert.YES | Alert.NO, null, 
				closeHandler, iconConfirm, Alert.NO);
			
			Alert.yesLabel = origLabelYes;
			Alert.noLabel = origLabelNo;			
		}
		
		/**
		 * 选择对话框提示
		 * @param message
		 * @param closehandler
		 * @param yesLabel
		 * @param noLabel
		 * @param cancelLabel
		 */		
		public static function choose(message:String, closeHandler:Function=null, 
			yesLabel:String="是", noLabel:String="否", cancelLabel:String="取消"):void{
				
			var origLabelYes:String = Alert.yesLabel;
			var origLabelNo:String = Alert.noLabel;				
			var origLabelCancel:String = Alert.cancelLabel;			
			if(yesLabel=="是") yesLabel = "是";
			if(noLabel=="否") noLabel = "否";
			if(cancelLabel=="取消") cancelLabel = "取消";
			Alert.yesLabel = yesLabel;
			Alert.noLabel = noLabel;
			Alert.cancelLabel = cancelLabel;
			
			CustomAlert.show(message, "选择确认", Alert.YES | Alert.NO | Alert.CANCEL, 
				null, closeHandler, iconConfirm, Alert.CANCEL);
			
			Alert.yesLabel = origLabelYes;
			Alert.noLabel = origLabelNo;					
			Alert.cancelLabel = origLabelCancel;					
		}	
		
	}
}